<?php
/**
 * 盈亏记录明细
 *
 *
 *
 * @copyright  Copyright (c) 2014-2015 TuntronKJ Inc. (http://www.tuntron.com)
 * @license    http://www.tuntron.com
 * @link       http://www.tuntron.com
 * @since      File available since Release v1.1
 */
defined('InTuntronKJ') or exit('Access Invalid!');
class userprofitlossdetailControl extends BaseLotteryHallControl{
	public function indexOp(){		
		$bets_model = Model('bat');
		$user_model = Model('member');
		$cash_model = Model('cash');
		
		$param = array();
		$uid = $_SESSION['uid'];
		$memberinfo = $user_model->getMemberInfo(array('uid'=>$uid));
		$param['username'] = $memberinfo['username'];
		
		$page = $_GET['pageIndex']?$_GET['pageIndex']:1;
		$start = 15*$page-15;
		
		$fromTime = strtotime($_GET['start']);
		$toTime = strtotime($_GET['end']);
		$liqType = $_GET['liqtype'];
		$param['liqtype'] = $liqType;
		
		if($fromTime && $toTime){
			$fromTime = $fromTime+3600*3;
			$toTime = $toTime+3600*3;
		}else{
			$today_zero = strtotime('today');
			$time = time();
			$fromTime = $today_zero+3600*3;			//查询起始时间
			if($fromTime > $time){
				$toTime = $fromTime;				//查询结束时间
				$fromTime = $today_zero-3600*21;

			}else{
				$toTime = $fromTime+3600*24;

			}
		}
		$param['beginDate'] = date('Y-m-d',$fromTime);
		$param['endDate'] = date("Y-m-d",$toTime);
		$condition['actionTime'] = array('between',$fromTime.','.$toTime);
		
		$condition['uid'] = $uid;		
		if($liqType == 1){
			//账户充值
			$condition['liqType'] = array('in',1);
		}elseif($liqType == 2){
			//账户提现
			$condition['liqType'] = array('in',101);
		}elseif($liqType == 3){
			//投注返点
			$condition['liqType'] = array('in',2);
		}elseif($liqType == 4){
			//游戏投注
			$condition['liqType'] = array('in',102);			
		}elseif($liqType == 5){
			//撤单返款
			$condition['liqType'] = array('in',7);
		}elseif($liqType == 6){
			//奖金派送
			$condition['liqType'] = array('in',6);
		}
		$profit_list = $bets_model->getCoinLogList($condition,'','',$start.',15');
		$profit_count = $bets_model->getCoinLogCount($condition);
		if($profit_count){
			$totalpage = ceil($profit_count/15);
		}else{
			$profit_count = 0;
			$totalpage = 1;
		}
		if(!empty($profit_list) && is_array($profit_list)){
			foreach($profit_list as $key => $value){
				$extfiled = explode('|', $value['extfield1']);
				$profit_list[$key]['lotteryName'] = $extfiled[0];
				$profit_list[$key]['ruleName'] = $extfiled[1];
				$profit_list[$key]['issueNumber'] = $extfiled[2];
			}
		}

		
		Tpl::output('profit_list',$profit_list);
		Tpl::output('param',$param);
		Tpl::output('page',$page);
		Tpl::output('totalpage',$totalpage);
		Tpl::output('count',count($profit_list));
		Tpl::showpage('userprofitlossdetail');
	}



}
